<!DOCTYPE html>

<!--[if lt IE 7 ]><html class="ie ie6" lang="en"> <![endif]-->
<!--[if IE 7 ]><html class="ie ie7" lang="en"> <![endif]-->
<!--[if IE 8 ]><html class="ie ie8" lang="en"> <![endif]-->
<!--[if (gte IE 9)|!(IE)]><!--><html lang="en"> <!--<![endif]-->
    <head>
        <meta charset="utf-8">
        <title>Training Your Fingers / Learn Vimscript the Hard Way</title>
        <meta name="description" content="">
        <meta name="author" content="Steve Losh">
        <!--[if lt IE 9]>
            <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
        <![endif]-->

        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

        <link href="/static/styles/skeleton/base.css" rel="stylesheet" type="text/css" />
        <link href="/static/styles/skeleton/skeleton.css" rel="stylesheet" type="text/css" />
        <link href="/static/styles/skeleton/layout.css" rel="stylesheet" type="text/css" />

        <link href="/static/styles/tango.css" rel="stylesheet" type="text/css" />
        <link href="/static/styles/style.less" rel="stylesheet/less" type="text/css" />

        <script type="text/javascript" src="/static/scripts/less.js"></script>
    </head>

    <body class="">
        <div class="container">
            <header class="sixteen columns">
                <h1><a href="/">Learn Vimscript the Hard Way</a></h1>
            </header>

            
    <section class="nav three columns">
        
<ul>
<li><a href="#training-your-fingers">Training Your Fingers</a><ul>
<li><a href="#learning-the-map">Learning the Map</a></li>
<li><a href="#exercises">Exercises</a></li>
</ul>
</li>
</ul>


        <div class="prevnext">
            
                <a class="prev" href="09.html">&laquo; Prev</a>
            
            
                <a class="next" href="11.html">Next &raquo;</a>
            
        </div>
    </section>

    <section class="content twelve columns offset-by-one">
        <div> 
<h1 id="training-your-fingers">Training Your Fingers</h1>
<p>In this chapter we're going to talk about how to learn Vim more effectively, but
we need to do a bit of preparation first.</p>
<p>Let's set up one more mapping that will save more wear on your left hand than
any other mapping you ever create.  Run the following command:</p>
<pre class="codehilite"><code class="language-vim">:inoremap jk &lt;esc&gt;</code></pre>


<p>Now enter insert mode and type <code>jk</code>.  Vim will act as if you pressed the escape
key and return you to normal mode.</p>
<p>There are a number of ways to exit insert mode in Vim by default:</p>
<ul>
<li><code>&lt;esc&gt;</code></li>
<li><code>&lt;c-c&gt;</code></li>
<li><code>&lt;c-[&gt;</code></li>
</ul>
<p>Each of those requires you to stretch your fingers uncomfortably.  Using <code>jk</code> is
great because the keys are right under two of your strongest fingers and you
don't have to perform a chord.</p>
<p>Some people prefer using <code>jj</code> instead of <code>jk</code>, but I prefer <code>jk</code> for two
reasons:</p>
<ul>
<li>It's typed with two separate keys, so you can "roll" your fingers instead of
  using the same one twice.</li>
<li>Pressing <code>jk</code> in normal mode out of habit will move down and then up, leaving
  you exactly where you started.  Using <code>jj</code> in normal mode will move you to
  a different place in your file.</li>
</ul>
<p>If you write in a language where <code>jk</code> is a frequently used combination of
letters (like Dutch) you'll probably want to pick a different mapping.</p>
<h2 id="learning-the-map">Learning the Map</h2>
<p>Now that you've got a great new mapping, how can you learn to use it?  Chances
are you've already got the escape key in your muscle memory, so when you're
editing you'll hit it without even thinking.</p>
<p>The trick to relearning a mapping is to <em>force</em> yourself to use it by
<em>disabling</em> the old key(s).  Run the following command:</p>
<pre class="codehilite"><code class="language-vim">:inoremap &lt;esc&gt; &lt;nop&gt;</code></pre>


<p>This effectively disables the escape key in insert mode by telling Vim to
perform <code>&lt;nop&gt;</code> (no operation) instead.  Now you <em>have</em> to use your <code>jk</code> mapping
to exit insert mode.</p>
<p>At first you'll forget, type escape and start trying to do something in normal
mode and you'll wind up with stray characters in your text.  It will be
frustrating, but if you stick with it you'll be surprised at how fast your mind
and fingers absorb the new mapping.  Within an hour or two you won't be
accidentally hitting escape any more.</p>
<p>This idea applies to any new mapping you create to replace an old one, and even
to life in general.  When you want to change a habit, make it harder or
impossible to do!</p>
<p>If you want to start cooking meals instead of microwaving TV dinners, don't buy
any TV dinners when you go shopping.  You'll cook some real food when you get
hungry enough.</p>
<p>If you want to quit smoking, always leave your cigarettes in your car's trunk.
When you get the urge to have a casual cigarette you'll think of what a pain in
the ass it will be to walk out to the car and are less likely to bother doing
it.</p>
<h2 id="exercises">Exercises</h2>
<p>If you still find yourself using the arrow keys to navigate around Vim in normal
mode, map them to <code>&lt;nop&gt;</code> to make yourself stop.</p>
<p>If you still use the arrow keys in insert mode, map them to <code>&lt;nop&gt;</code> there too.
The right way to use Vim is to get out of insert mode as soon as you can and use
normal mode to move around.</p></div>

        <div class="prevnext">
            
                <a class="prev" href="09.html">&laquo; Previous</a>
            
            
                <a class="next" href="11.html">Next &raquo;</a>
            
        </div>
    </section>


            <footer class="sixteen columns">
                Made by <a href="http://stevelosh.com">Steve Losh</a>.

                <a href="/license.html">License</a>.

                Built with
                <a href="http://bitbucket.org/sjl/bookmarkdown/">Bookmarkdown</a>.
            </footer>
        </div>

        
            <script type="text/javascript">
                var _gaq = _gaq || [];
                _gaq.push(['_setAccount', 'UA-15328874-8']);
                _gaq.push(['_trackPageview']);

                (function() {
                 var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
                 ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
                 var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
                 })();
            </script>
        

        
            <script type="text/javascript">
                var _gauges = _gauges || [];
                (function() {
                 var t   = document.createElement('script');
                 t.type  = 'text/javascript';
                 t.async = true;
                 t.id    = 'gauges-tracker';
                 t.setAttribute('data-site-id', '4e8f83b7f5a1f546e200000d');
                 t.src = '//secure.gaug.es/track.js';
                 var s = document.getElementsByTagName('script')[0];
                 s.parentNode.insertBefore(t, s);
                 })();
             </script>
        
    </body>
</html>
